﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wind.Cloud.Tools
{
    public class SearchList<T>
    {
        /// <summary>
        /// 搜尋是否物件某屬性中是否帶有某關鍵字
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lists"></param>
        /// <param name="propertyName">屬性名</param>
        /// <param name="propertyValue">是否包含某關鍵字</param>
        /// <returns></returns>
        public T[] SearchListPropertyValue<T>(List<T> lists, string propertyName, string propertyValue)
        {
            List<T> re = new List<T>();
            return
                lists.Where(
                    x => x.GetType().GetProperty(propertyName).GetValue(x, null).ToString().IndexOf(propertyValue, StringComparison.OrdinalIgnoreCase) >= 0).
                    ToArray();
            //foreach (var obj in lists)
            //{
            //    if(obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString().IndexOf(propertyValue,StringComparison.OrdinalIgnoreCase)>=0)
            //    {
            //        re.Add(obj);
            //    }
            //}
            //return re.ToArray();
        }
    }
}
